package com.bango.android;

import java.lang.reflect.Constructor;
import java.util.Date;
import java.util.TimeZone;

import android.content.Context;
import android.net.ConnectivityManager;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class BangoStatic
{

	public static Date GetUTCDate()
	{
		Date utcDate = new Date();
		TimeZone timeZone = TimeZone.getDefault();
		utcDate = new Date(utcDate.getTime() + (timeZone.getOffset(utcDate.getTime()) * -1));
		return utcDate;
	}

	public static String ConnectionType(int connectionType)
	{
		String returnValue = "OTHER";

		switch (connectionType) {
			case ConnectivityManager.TYPE_WIFI:
				returnValue = "WIFI";
				break;
			case ConnectivityManager.TYPE_MOBILE:
				returnValue = "OPERATOR";
				break;
		}

		return returnValue;
	}

	public static String OperatorConnectionType(int operatorConnectionType)
	{

		String returnValue = "OTHER";
		switch (operatorConnectionType) {
			case android.telephony.TelephonyManager.NETWORK_TYPE_GPRS:
				returnValue = "GPRS";
				break;
			case android.telephony.TelephonyManager.NETWORK_TYPE_UMTS:
				returnValue = "UMTS";
				break;
			case android.telephony.TelephonyManager.NETWORK_TYPE_EDGE:
				returnValue = "EDGE";
				break;
		}

		return returnValue;
	}

	public static String GetUserAgent(Context context) {
		String userAgent = null;
	    try {
	        Constructor<WebSettings> constructor = WebSettings.class.getDeclaredConstructor(Context.class, WebView.class);
	        constructor.setAccessible(true);
	        try {
	            WebSettings settings = constructor.newInstance(context, null);
	            userAgent = settings.getUserAgentString();
	        } finally {
	            constructor.setAccessible(false);
	        }
	    } 
	    catch (Exception e) {
	    	try
	    	{
		        if(Thread.currentThread().getName().equalsIgnoreCase("main")){
		            WebView m_webview = new WebView(context);
		            userAgent = m_webview.getSettings().getUserAgentString();
		        }
	    	}
	    	catch(Exception e2)
	    	{
	    		
	    	}
	    }
        return userAgent;
	}
}
